import React from 'react';
import { withRouter } from 'react-router-dom';
import { inject, observer } from 'mobx-react';
import { TreePage } from 'weaver-mobile-page';
import { renderLoading } from '../../public/BlogUtils';
import HisBlogRoute from '../../hisBlog/HisBlogRoute';

const Tree = TreePage.Normal;
@inject('blogAttentionStore')
@withRouter
@observer
export default class Organization extends React.Component {
  static defaultProps = {
    prefixCls: 'blog-center-attention-organization'
  }

  constructor(props) {
    super(props);
    this.state = {
      path: props.parentPath + "/hisBlog/",
      userId: '',
      isCON:1

    };
  }

  componentDidMount() {
    const { blogAttentionStore: { organizationStore } } = this.props;
    organizationStore.initTree();
  }

  handleSelect = (key, data, level) => {
    // console.log(key, data, level);
    this.setState({ userId: data.id }, () => {
      this.props.history.push("/userCenter/blogAttention/attention/hisBlog/" + data.id);
    });
  }

  render() {
    const { prefixCls, blogAttentionStore: { organizationStore } } = this.props;
    const { treeStore, params, loading } = organizationStore;

       return this.state.userId ?  <div className={prefixCls}>
          <HisBlogRoute path={this.state.path}  userId={this.state.userId}/>
      </div>:  loading ? renderLoading : (
          <div className={prefixCls} style={{"bottom": 50}}>
              <Tree
                  async
                  store={treeStore}
                  params={params}
                  onSelect={this.handleSelect}
              />
          </div>
      )
    }

}